#!/bin/bash
set -ex

cd $(dirname $0)/..

. ./hack/version.sh

RUNC_DIR=build/src/github.com/opencontainers/runc
DATA_DIR=build/data
CHARTS_DIR=build/static/charts
NERDCTL_VERSION=0.14.0
CILIUMCLI_VERSION=v0.9.3

umask 022
rm -rf ${CHARTS_DIR}
rm -rf ${RUNC_DIR}
mkdir -p ${DATA_DIR}
mkdir -p ${CHARTS_DIR}
mkdir -p bin

git clone --single-branch --branch=${VERSION_RUNC} --depth=1 https://github.com/opencontainers/runc ${RUNC_DIR}

#nerdctl for containerd , 0.14.0
echo "download nerdctl..."
if [ ${ARCH} = amd64 ]; then
  curl --compressed -sfL https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz | tar zxf - -C bin
elif [ ${ARCH} = aarch64 ] || [ ${ARCH} = arm64 ]; then
  curl --compressed -sfL https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-arm64.tar.gz | tar zxf - -C bin
fi

# Cilium-cli
echo "download Cilium-cli..."
if [ ${ARCH} = amd64 ]; then
  curl --compressed -sfL https://github.com/cilium/cilium-cli/releases/download/${CILIUMCLI_VERSION}/cilium-linux-amd64.tar.gz | tar zxf - -C bin
elif [ ${ARCH} = aarch64 ] || [ ${ARCH} = arm64 ]; then
  curl --compressed -sfL https://github.com/cilium/cilium-cli/releases/download/${CILIUMCLI_VERSION}/cilium-linux-arm64.tar.gz | tar zxf - -C bin
fi